package com.yifeng.repo.flink.data.transport.dto;

import com.google.common.base.Strings;

import java.util.Map;

public class DataRow {

    private Type op;

    private Map<String,Object> before;

    private Map<String,Object> after;

    private String schema;

    private String tb;

    private Long  ts_ms;
    
    private String database;

    private DataRow() {
    }

    public DataRow(Type op, Map<String, Object> after, String schema, String tb, String database) {
        this.op = op;
        this.after = after;
        this.before = null;
        this.schema = schema;
        this.tb = tb;
        this.database = database;
    }

    public DataRow(Type op, Map<String, Object> before, Map<String, Object> after, String schema, String tb, String database) {
        this.op = op;
        this.before = before;
        this.after = after;
        this.schema = schema;
        this.tb = tb;
        this.database = database;
    }

    public enum Type {
        /**
         * 新增行
         */
        c,
        /**
         * 存量行
         */
        r,
        /**
         * 更新行
         */
        u,
        /**
         * 删除行
         */
        d,
        /**
         * 结束标记
         */
        end,
        /**
    * ddl操作
         */
        ddl;
    	public static Type parse(String type) {
	        if (Strings.isNullOrEmpty(type)) {
	            return null;
	        }
	        if ("c".equals(type)) {
                return Type.c;
            }
	        if ("r".equals(type)) {
                return Type.r;
            }
            if ("u".equals(type)) {
                return Type.u;
            }
            if ("d".equals(type)) {
                return Type.d;
            }
            if ("ddl".equals(type)) {
                return Type.ddl;
            }
	        return null;
	    }
    }

    public Type getOp() {
        return op;
    }

    public void setOp(Type op) {
        this.op = op;
    }

    public Map<String, Object> getBefore() {
        return before;
    }

    public void setBefore(Map<String, Object> before) {
        this.before = before;
    }

    public Map<String, Object> getAfter() {
        return after;
    }

    public void setAfter(Map<String, Object> after) {
        this.after = after;
    }

    public String getSchema() {
        return schema;
    }

    public void setSchema(String schema) {
        this.schema = schema;
    }

    public String getTb() {
        return tb;
    }

    public void setTb(String tb) {
        this.tb = tb;
    }

    public Long getTs_ms() {
        return ts_ms;
    }

    public void setTs_ms(Long ts_ms) {
        this.ts_ms = ts_ms;
    }
    
    public String getDatabase() {
		return database;
	}

	public void setDatabase(String database) {
		this.database = database;
	}

	@Override
    public String toString() {
        return "DataRow{" +
                "op=" + op +
                ", before=" + before +
                ", after=" + after +
                ", schema='" + schema + '\'' +
                ", tb='" + tb + '\'' +
                ", ts_ms=" + ts_ms +
                ", database='" + database + '\'' +
                '}';
    }
}
